package com.qf.lyw1225.springboot.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.lyw1225.springboot.entity.User;
import com.qf.lyw1225.springboot.service.UserService;
import com.qf.lyw1225.springboot.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author HP
 */

@Api(tags = "分页查询、修改模块")
@RestController
@CrossOrigin
public class UserController {

    @Resource
    private UserService userService;


    /**
     * 修改用户信息
     */
    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public Result<User> update(@RequestBody User user) {
        return userService.update(user);
    }

    /**
     * 分页查询完善
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "分页查询+模糊查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页码", required = true),
            @ApiImplicitParam(name = "pageSize", value = "查询数据的页数", required = true)
    }
    )
    @GetMapping("/page")
    public IPage<User> getUsers(
            @RequestParam(defaultValue = "1") Integer pageNum,  // 默认页码为 1
            @RequestParam(defaultValue = "2") Integer pageSize, // 默认每页 10 条
            @RequestParam(defaultValue = "") String username
    ) {
        return userService.queryPage(pageNum, pageSize, username);
    }


}
